package com.api.gbhg.daiyanlu.Dao;

import com.api.gbhg.zengping.dao.PropertyManagementCostDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import weaver.conn.RecordSet;
import weaver.conn.RecordSetTrans;

/**
 * 打印纸复印纸用量
 * Mr.dyl
 */
public class PrintCopyActionDao {
    public static final Logger log= LoggerFactory.getLogger(PropertyManagementCostDao.class);

    public RecordSetTrans getMainTable(String requestId){
        RecordSetTrans rts=new RecordSetTrans();
        StringBuffer sb=new StringBuffer();
        String sql =" select v.lcjlsqjlid, v.lcid,v.xmmin,v.sbdw,v.sbks,v.jbr,v.yszje,f.hwgz,f.zfcgyswy,f.gc,f.fw,f.xecg,f.requestId from uf_jingfei_version v \n" +
                "                                INNER JOIN uf_fyzdyzylxqbbb f on v.lcjlsqjlid =f.requestId where 1=1";
        sb.append(sql);
        try {
            if(!requestId.equals(" ")){
                sb.append(" AND f.requestId in ("+requestId+")");
            }else {
                return null;
            }
            //通过分页公式计算下一页在哪一行开始
            //如1，10，1-1 = 0，那第一条开始显示下面十条，第一页
            //如2，10，(2-1)乘以10 = 10，那就是第十条开始显示下面十条，第二页
            // 判断是mysql 还是sqlserver
//            pageNum=(pageNum-1)*pageSize;
//            if("sqlserver".equals(rts.getDBType())){
//                sb.append(" order by v.Id offset "+pageNum+" rows fetch next "+pageSize+" rows only");
//            }else if("mysql".equals(rts.getDBType())){
//                sb.append(" LIMIT "+pageNum+","+pageSize+"");
//            }
            log.info("打印纸复印纸用量主表sql:--->"+sb.toString());
            rts.executeQuery(sb.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return rts;
    }

    //获取数据条数
    public int getMainTableCount(String status){
        RecordSet rs = new RecordSet();
        String StrSQL ="select COUNT(1)AS num from uf_jingfei_version v INNER JOIN uf_fyzdyzylxqbbb b on v.lcjlsqjlid =b.requestId where 1=1";
        if(status.equals("3")){
            StrSQL=StrSQL+(" AND lcztz="+status);
        }else {
            StrSQL=StrSQL+(" AND lcztz<> 3");
        }
        log.info("打印纸复印纸用量总条数sql:--->"+StrSQL);
        rs.executeQuery(StrSQL);
        rs.next();
        return rs.getInt("num");
    }

    public RecordSet getDetailedTable(String requestid,int table){
        RecordSet rs = new RecordSet();
        String StrSQL="";
        if (table==1){
            StrSQL = "select * from uf_fyzdyzylxqbbb_dt1 where mainid="+"(select id from uf_fyzdyzylxqbbb where requestid=" + requestid+")"; //获取明细条1
        }else if (table==2){
            StrSQL = "select * from uf_fyzdyzylxqbbb_dt2 where mainid="+"(select id from uf_fyzdyzylxqbbb where requestid=" + requestid+")"; //获取明细条2
        }
        log.info("复印纸打印纸用量明细表sql:--->"+StrSQL);
        rs.executeQuery(StrSQL);
        return rs;
    }

    public RecordSet getEducationFundStorage(String requestid) {
        RecordSet rs = new RecordSet();
        String StrSQL = "select v.jbr,v.sbdw,v.xmmin,v.lcbj,v.lcjlsqjlid,v.gkdw,v.sydw,d.bmyszcjjfl,d.dyzfjjfl,v.ysnd,v.yszje,d.hjwy from uf_jingfei_version v INNER JOIN uf_hgylbxjfjfxqb j ON v.requestId=j.requestId INNER JOIN uf_hgylbxjfjfxqb_dt2 d ON d.mainid= j.id WHERE v.requestId= " + requestid;
        log.info("海关养老保险缴费经费入库:--->" + StrSQL);
        rs.executeQuery(StrSQL, new Object[0]);
        return rs;
    }
}
